define(['./../initial', './../controller/statistic/statisticCtrl', './../controller/statistic/statistic.projectCtrl', './../controller/statistic/statistic.lineLongCtrl', './../controller/statistic/statistic.lineCriticalCtrl', './../model/Project'], function () {
    var app = angular.module('App.home');
    app.config(['$stateProvider', '$urlRouterProvider', '$locationProvider',
        function ($stateProvider, $urlRouterProvider, $locationProvider) {



            $stateProvider
                .state('statistic', {
                    url: "/statistic/{projectTypeCode:[a-zA-Z]+}",
                    resolve: {
                        //提前获取权限项目
                        allProjects: ['Project', '$stateParams', function (Project, $stateParams) {
                            if ($stateParams.projectTypeCode === 'LongTermSubChord' || $stateParams.projectTypeCode === 'CriticalSectionMonitor') {
                                return Project.getAllCityList($stateParams.projectTypeCode)
                                    .then(function (cityList) {
                                        cityList.forEach(function (city) {
                                            city.lines.forEach(function (line) {
                                                line.projects = line.projects.filter(function (project) {
                                                    return project.monitorTypes.indexOf('收敛') >= 0;
                                                });
                                            });
                                        });
                                        return cityList;
                                    });
                            } else {
                                $state.go('login');
                            }
                        }]
                    },
                    templateUrl: "/partials/statistic/statistic",
                    controller: "statisticCtrl"
                })
                .state('statistic.project', {
                    url: "/project/{prjId:[0-9]+}",
                    resolve: {
                        //提前获取权限项目
                        curPrj: ['$state', 'allProjects', '$stateParams', 'Project', function ($state, allProjects, $stateParams, Project) {
                            var curPrj = Project.getCurProject($stateParams.prjId, allProjects);
                            if (curPrj === null) {
                                $state.go('projects');
                            } else {
                                return curPrj;
                            }
                        }],
                        locationList: ['curPrj', function (curPrj) {
                            return curPrj.getLocationList('收敛');
                        }]
                    },
                    templateUrl: "/partials/statistic/statistic/project",
                    controller: "statistic.projectCtrl"
                })
                .state('statistic.lineLong', {
                    url: "/lineLong/{lineId:[0-9]+}",
                    resolve: {
                        //提前获取权限项目
                        curLine: ['$state', 'allProjects', '$stateParams', 'Project', function ($state, allProjects, $stateParams, Project) {
                            var curLine = Project.getCurLine($stateParams.lineId, allProjects);
                            if (curLine === null) {
                                $state.go('projects');
                            } else {
                                return curLine;
                            }
                        }]
                    },
                    templateUrl: "/partials/statistic/statistic/lineLong",
                    controller: "statistic.lineLongCtrl"
                }).state('statistic.lineCritical', {
                    url: "/lineCritical/{lineId:[0-9]+}",
                    resolve: {
                        //提前获取权限项目
                        curLine: ['$state', 'allProjects', '$stateParams', 'Project', function ($state, allProjects, $stateParams, Project) {
                            var curLine = Project.getCurLine($stateParams.lineId, allProjects);
                            if (curLine === null) {
                                $state.go('projects');
                            } else {
                                return curLine;
                            }
                        }]
                    },
                    templateUrl: "/partials/statistic/statistic/lineCritical",
                    controller: "statistic.lineCriticalCtrl"
                });



        }
    ]);
});
